<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Index extends Base{
    /**
    *小程序部分
    */
    private function httpRequest($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    //openid
    public function openid(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.code"))){
            $code=input("param.code");
        }else{
            return json(['code' => 503, 'msg' => '请给code']);exit();
        }
        $aboutus=Db::name('aboutus')->where('cus_id',$cus_id)->find();
        $url="https://api.weixin.qq.com/sns/jscode2session?appid=".$aboutus['appid']."&secret=".$aboutus['appsecret']."&js_code=".$code."&grant_type=authorization_code";
        $res=$this->httpRequest($url);
        if($res){
            return json(['code' => 200, 'msg' => '成功！','data'=>json_decode($res)]);exit();
        }else{
            return json(['code' => 500, 'msg' => '失败！']);exit();
        }
    }
    //如果存在openid不需要保存授权和保存用户信息
    public function isopenid(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => '请给openid']);exit();
        }
        $res=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
        if($res){
            return json(['code' => 200, 'msg' => '存在！']);exit();
        }else{
            return json(['code' => 500, 'msg' => '不存在！']);exit();
        }
    }
    //保存用户信息
    public function userinfoin(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => '请给openid']);exit();
        }
        if(!empty(input("param.avatar"))){
            $avatar=input("param.avatar");
        }else{
            return json(['code' => 504, 'msg' => '请给头像']);exit();
        }
        if(!empty(input("param.nickname"))){
            $nickname=input("param.nickname");
        }else{
            return json(['code' => 505, 'msg' => '请给昵称']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $user=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
                if($user){
                    return json(['code' => 201, 'msg' => '用户已存在！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['openid']=$openid;
                    $data['avatar']=$avatar;
                    $data['nickname']=$nickname;
                    $data['time']=time();
                    $userin=Db::name('users')->insert($data);
                    if($userin){
                        return json(['code' => 200, 'msg' => '成功保存用户！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '保存失败！']);exit();
                    }
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $user=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
                if($user){
                    return json(['code' => 201, 'msg' => '用户已存在！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['openid']=$openid;
                    $data['avatar']=$avatar;
                    $data['nickname']=$nickname;
                    $data['time']=time();
                    $userin=Db::name('users')->insert($data);
                    if($userin){
                        return json(['code' => 200, 'msg' => '成功保存用户！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '保存失败！']);exit();
                    }
                }
            }else{
                return json(['code' => 506, 'msg' => '未开启此平台！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //主题色
    public function themecolor(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $themecolor['template']=$customer['template'];
            if($customer['themefont']==1){  
                $themecolor['themefont']='#000000';
            }elseif($customer['themefont']==2){
                $themecolor['themefont']='#ffffff';
            }
            $themecolor['themecolor']=$customer['themecolor'];
            $themecolor['backcolor']=$customer['backcolor'];
            $themecolor['bottomcolor']=$customer['bottomcolor'];
            return json(['code' => 200, 'msg' => '成功！','data'=>$themecolor]);exit();
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //首页新需求样式
    public function indexstyle(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $indexstyle['search_state']=$customer['search_state'];
            $indexstyle['bannerw']=$customer['bannerw'];
            $indexstyle['bannerh']=$customer['bannerh'];
            $indexstyle['inavs']=$customer['inavs'];
            $indexstyle['bnavh']=$customer['bnavh'];
            $indexstyle['bnavs']=$customer['bnavs'];
            return json(['code' => 200, 'msg' => '成功！','data'=>$indexstyle]);exit();
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //模块设置
    public function moduleset(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $moduleset=Db::name('moduleset')->where('cus_id',$cus_id)->order('id asc')->select();
                if($moduleset){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$moduleset]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $moduleset=Db::name('moduleset')->where('cus_id',$cus_id)->order('id asc')->select();
                if($moduleset){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$moduleset]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $moduleset=Db::name('moduleset')->where('cus_id',$cus_id)->order('id asc')->select();
                if($moduleset){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$moduleset]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //轮播图
    public function banner(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $banner=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',0)->order('sort desc')->select();
                if($banner){
                    foreach ($banner as $key => $value) {
                        $banner[$key]['time']=date('Y-m-d H:i:s',$banner[$key]['time']);
                        $banner[$key]['uptime']=date('Y-m-d H:i:s',$banner[$key]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$banner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $banner=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',0)->order('sort desc')->select();
                if($banner){
                    foreach ($banner as $key => $value) {
                        $banner[$key]['time']=date('Y-m-d H:i:s',$banner[$key]['time']);
                        $banner[$key]['uptime']=date('Y-m-d H:i:s',$banner[$key]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$banner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $banner=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',0)->order('sort desc')->select();
                if($banner){
                    foreach ($banner as $key => $value) {
                        $banner[$key]['time']=date('Y-m-d H:i:s',$banner[$key]['time']);
                        $banner[$key]['uptime']=date('Y-m-d H:i:s',$banner[$key]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$banner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //轮播图跳转详情页
    public function bannerdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.pcn"))){
            $pcn=input("param.pcn");
        }else{
            return json(['code' => 503, 'msg' => '轮播图类型呢']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 504, 'msg' => '轮播图详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                if($pcn==1){
                    $detail=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==2){
                    $detail=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==3){
                    $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                if($pcn==1){
                    $detail=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==2){
                    $detail=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==3){
                    $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                if($pcn==1){
                    $detail=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==2){
                    $detail=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($pcn==3){
                    $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //公告
    public function comad(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $comads=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(3)->select();
                if($comads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $comads=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(3)->select();
                if($comads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $comads=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(3)->select();
                if($comads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //公告跳转详情页
    public function comaddetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '公告详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $detail=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //导航栏
    public function nav(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $navs=Db::name('nav')->where('nav_type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $navs=Db::name('nav')->where('nav_type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $navs=Db::name('nav')->where('nav_type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //模板9单页列表
    public function singlelist(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $singles=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->order('id desc')->select();
                if($singles){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$singles]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $singles=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->order('id desc')->select();
                if($singles){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$singles]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $singles=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->order('id desc')->select();
                if($singles){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$singles]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //获取单页数据
    public function singledetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '单页id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['detail'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['detail']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['detail'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['detail']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $detail=Db::name('single')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['detail'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['detail']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //底部导航栏
    public function tabBar(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        $shopstate=Db::name('aboutus')->where('cus_id',$cus_id)->value('shopstate');
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $navs=Db::name('nav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    for ($i=0; $i <count($navs) ; $i++) { 
                        $tabs[$i]['selected']='false';
                        $tabs[$i]['type']=$navs[$i]['link_style'];
                        if($navs[$i]['link_style']==1){
                            $tabs[$i]['pagePath']=$navs[$i]['single'];
                        }elseif($navs[$i]['link_style']==2){
                            $tabs[$i]['pagePath']=$navs[$i]['wxpage'];
                            $tabs[$i]['appname']=$navs[$i]['wxappid'];
                        }elseif($navs[$i]['link_style']==3){
                            $tabs[$i]['pagePath']=$navs[$i]['webpage'];
                        }elseif($navs[$i]['link_style']==4){
                            $tabs[$i]['pagePath']=$navs[$i]['telphone'];
                        }else{
                            $tabs[$i]['pagePath']=$navs[$i]['nav_link'];
                            if($navs[$i]['nav_link']=='/pages/product/product'&&$shopstate==1){
                                $tabs[$i]['pagePath']='/pages/mallHome/mallHome';
                            }
                        }
                        $tabs[$i]['text']=$navs[$i]['nav_name'];
                        $tabs[$i]['iconPath']=$navs[$i]['nav_ico'];
                        $tabs[$i]['selectedIconPath']=$navs[$i]['imgt'];
                    }
                    $tabs[0]['selected']='true';
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tabs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $navs=Db::name('nav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    for ($i=0; $i <count($navs) ; $i++) { 
                        $tabs[$i]['selected']='false';
                        $tabs[$i]['type']=$navs[$i]['link_style'];
                        if($navs[$i]['link_style']==1){
                            $tabs[$i]['pagePath']=$navs[$i]['single'];
                        }elseif($navs[$i]['link_style']==2){
                            $tabs[$i]['pagePath']=$navs[$i]['bdpage'];
                            $tabs[$i]['appname']=$navs[$i]['bdappid'];
                        }elseif($navs[$i]['link_style']==3){
                            $tabs[$i]['pagePath']=$navs[$i]['webpage'];
                        }elseif($navs[$i]['link_style']==4){
                            $tabs[$i]['pagePath']=$navs[$i]['telphone'];
                        }else{
                            $tabs[$i]['pagePath']=$navs[$i]['nav_link'];
                            if($navs[$i]['nav_link']=='/pages/product/product'&&$shopstate==1){
                                $tabs[$i]['pagePath']='/pages/mallHome/mallHome';
                            }
                        }
                        $tabs[$i]['text']=$navs[$i]['nav_name'];
                        $tabs[$i]['iconPath']=$navs[$i]['nav_ico'];
                        $tabs[$i]['selectedIconPath']=$navs[$i]['imgt'];
                    }
                    $tabs[0]['selected']='true';
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tabs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $navs=Db::name('nav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort asc')->select();
                if($navs){
                    for ($i=0; $i <count($navs) ; $i++) { 
                        $tabs[$i]['selected']='false';
                        $tabs[$i]['type']=$navs[$i]['link_style'];
                        if($navs[$i]['link_style']==1){
                            $tabs[$i]['pagePath']=$navs[$i]['single'];
                        }elseif($navs[$i]['link_style']==2){
                            $tabs[$i]['pagePath']=$navs[$i]['zjpage'];
                            $tabs[$i]['appname']=$navs[$i]['zjappid'];
                        }elseif($navs[$i]['link_style']==3){
                            $tabs[$i]['pagePath']=$navs[$i]['webpage'];
                        }elseif($navs[$i]['link_style']==4){
                            $tabs[$i]['pagePath']=$navs[$i]['telphone'];
                        }else{
                            $tabs[$i]['pagePath']=$navs[$i]['nav_link'];
                            if($navs[$i]['nav_link']=='/pages/product/product'&&$shopstate==1){
                                $tabs[$i]['pagePath']='/pages/mallHome/mallHome';
                            }
                        }
                        $tabs[$i]['text']=$navs[$i]['nav_name'];
                        $tabs[$i]['iconPath']=$navs[$i]['nav_ico'];
                        $tabs[$i]['selectedIconPath']=$navs[$i]['imgt'];
                    }
                    $tabs[0]['selected']='true';
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tabs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //产品分类名
    public function procate(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $procates=Db::name('cate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($procates){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$procates]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $procates=Db::name('cate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($procates){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$procates]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $procates=Db::name('cate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($procates){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$procates]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //产品所有对应的产品
    public function productalls(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //产品分类名对应的产品
    public function products(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cate_id"))){
            $cate_id=input("param.cate_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出分类名的id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $products=Db::name('product')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $products=Db::name('product')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $products=Db::name('product')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
                if($products){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //产品跳转详情
    public function prodetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '产品详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('product')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['attrarrs']=json_decode($detail['attrarrs']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('product')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    $detail['attrarrs']=json_decode($detail['attrarrs']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $detail=Db::name('product')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    $detail['attrarrs']=json_decode($detail['attrarrs']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //新闻资讯
    public function news(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->find();
                if($news){
                    $news['uptime']=date('Y-m-d H:i:s',$news['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$news]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->find();
                if($news){
                    $news['uptime']=date('Y-m-d H:i:s',$news['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$news]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->find();
                if($news){
                    $news['uptime']=date('Y-m-d H:i:s',$news['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$news]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //新闻动态跳转详情
    public function newdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '新闻详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('news')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('news')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $detail=Db::name('news')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //广告
    public function ad(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $ads=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',6)->order('sort desc')->find();
                if($ads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$ads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $ads=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',6)->order('sort desc')->find();
                if($ads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$ads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $ads=Db::name('banner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',6)->order('sort desc')->find();
                if($ads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$ads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //关于我们
    public function about(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $about=Db::name('aboutus')->where('cus_id',$cus_id)->find();
                if($about){
                    $about['call_more']=json_decode($about['call_more']);
                    $about['about'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$about['about']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$about]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $about=Db::name('aboutus')->where('cus_id',$cus_id)->find();
                if($about){
                    $about['about'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$about['about']);
                    $about['call_more']=json_decode($about['call_more']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$about]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $about=Db::name('aboutus')->where('cus_id',$cus_id)->find();
                if($about){
                    $about['about'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$about['about']);
                    $about['call_more']=json_decode($about['call_more']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$about]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //合作伙伴
    public function partner(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $partner=Db::name('partner')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($partner){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$partner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $partner=Db::name('partner')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($partner){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$partner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $partner=Db::name('partner')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($partner){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$partner]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //案例
    public function cases(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $casea=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(4)->select();
                if($casea){
                    for ($i=0; $i <count($casea) ; $i++) { 
                        $casea[$i]['times']=date('Y-m-d',$casea[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$casea]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $casea=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(4)->select();
                if($casea){
                    for ($i=0; $i <count($casea) ; $i++) { 
                        $casea[$i]['times']=date('Y-m-d',$casea[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$casea]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $casea=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('flag',1)->order('sort desc')->limit(4)->select();
                if($casea){
                    for ($i=0; $i <count($casea) ; $i++) { 
                        $casea[$i]['times']=date('Y-m-d',$casea[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$casea]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //案例跳转详情
    public function casedetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '案例详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('case')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('case')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $detail=Db::name('case')->where('id',$id)->where('cus_id',$cus_id)->where('state',1)->find();
                if($detail){
                    $detail['content'] = str_replace('<img src="','<img src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['content'] = str_replace('<source src="','<source src="'.config('tmdhttp').$_SERVER['HTTP_HOST'],$detail['content']);
                    $detail['uptime']=date('Y-m-d H:i:s',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //混合搜索
    public function pcnsearch(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.key"))){
            $key=input('param.key');
        }else{
            return json(['code' => 503, 'msg' => '搜索关键词呢']);exit();
        }
        if(!empty(input("param.page"))){
            $page=input("param.page");
        }else{
            return json(['code' => 504, 'msg' => '当前分页数']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $cases=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                if($products||$cases||$news){
                    for ($i=0; $i <count($products) ; $i++) {
                        $products[$i]['type']=1;
                        $products[$i]['time']=date('Y/m/d',$products[$i]['time']);
                        $products[$i]['uptime']=date('Y-m-d H:i:s',$products[$i]['uptime']);
                    }
                    for ($i=0; $i <count($cases) ; $i++) {
                        $cases[$i]['type']=2;
                        $cases[$i]['time']=date('Y/m/d',$cases[$i]['time']);
                        $cases[$i]['uptime']=date('Y-m-d H:i:s',$cases[$i]['uptime']);
                        array_push($products,$cases[$i]);
                    }
                    for ($i=0; $i <count($news) ; $i++) {
                        $news[$i]['type']=3;
                        $news[$i]['time']=date('Y/m/d',$news[$i]['time']);
                        $news[$i]['uptime']=date('Y-m-d H:i:s',$news[$i]['uptime']);
                        array_push($products,$news[$i]);
                    }
                    return json(['code' => 200, 'msg' => '成功！','key'=>$key,'data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $cases=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                if($products||$cases||$news){
                    for ($i=0; $i <count($products) ; $i++) {
                        $products[$i]['type']=1;
                        $products[$i]['time']=date('Y/m/d',$products[$i]['time']);
                        $products[$i]['uptime']=date('Y-m-d H:i:s',$products[$i]['uptime']);
                    }
                    for ($i=0; $i <count($cases) ; $i++) {
                        $cases[$i]['type']=2;
                        $cases[$i]['time']=date('Y/m/d',$cases[$i]['time']);
                        $cases[$i]['uptime']=date('Y-m-d H:i:s',$cases[$i]['uptime']);
                        array_push($products,$cases[$i]);
                    }
                    for ($i=0; $i <count($news) ; $i++) {
                        $news[$i]['type']=3;
                        $news[$i]['time']=date('Y/m/d',$news[$i]['time']);
                        $news[$i]['uptime']=date('Y-m-d H:i:s',$news[$i]['uptime']);
                        array_push($products,$news[$i]);
                    }
                    return json(['code' => 200, 'msg' => '成功！','key'=>$key,'data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==3&&$customer['platformtt_state']==1){
                $products=Db::name('product')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $cases=Db::name('case')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                $news=Db::name('news')->where('cus_id',$cus_id)->where('state',1)->where('title','like',"%{$key}%")->order('id desc')->limit(4*($page-1),4)->select();
                if($products||$cases||$news){
                    for ($i=0; $i <count($products) ; $i++) {
                        $products[$i]['type']=1;
                        $products[$i]['time']=date('Y/m/d',$products[$i]['time']);
                        $products[$i]['uptime']=date('Y-m-d H:i:s',$products[$i]['uptime']);
                    }
                    for ($i=0; $i <count($cases) ; $i++) {
                        $cases[$i]['type']=2;
                        $cases[$i]['time']=date('Y/m/d',$cases[$i]['time']);
                        $cases[$i]['uptime']=date('Y-m-d H:i:s',$cases[$i]['uptime']);
                        array_push($products,$cases[$i]);
                    }
                    for ($i=0; $i <count($news) ; $i++) {
                        $news[$i]['type']=3;
                        $news[$i]['time']=date('Y/m/d',$news[$i]['time']);
                        $news[$i]['uptime']=date('Y-m-d H:i:s',$news[$i]['uptime']);
                        array_push($products,$news[$i]);
                    }
                    return json(['code' => 200, 'msg' => '成功！','key'=>$key,'data'=>$products]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
}